package com.example.file_management.config;


//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.sql.DataSource;
//
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//    basePackages = "com.example.file_management.mapper.user",
//    entityManagerFactoryRef = "userEntityManagerFactory",
//    transactionManagerRef = "userTransactionManager"
//)
//class UserJpaConfig {
//
//    @Primary
//    @Bean(name = "userJpaDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.user")
//    public DataSource userJpaDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Primary
//    @Bean(name = "userEntityManagerFactory")
//    public LocalContainerEntityManagerFactoryBean userEntityManagerFactory(
//            EntityManagerFactoryBuilder builder,
//            @Qualifier("userJpaDataSource") DataSource dataSource) {
//        return builder
//                .dataSource(dataSource)
//                .packages("com.example.file_management.pojo.user") // 替换为你的实体类所在的包
//                .persistenceUnit("user")
//                .build();
//    }
//
//    @Primary
//    @Bean(name = "userTransactionManager")
//    public PlatformTransactionManager userTransactionManager(
//            @Qualifier("userEntityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory) {
//        return new JpaTransactionManager(entityManagerFactory.getObject());
//    }
//}
//
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//    basePackages = "com.example.file_management.mapper.material",
//    entityManagerFactoryRef = "materialEntityManagerFactory",
//    transactionManagerRef = "materialTransactionManager"
//)
//class MaterialJpaConfig {
//
//    @Bean(name = "materialJpaDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.material")
//    public DataSource materialJpaDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "materialEntityManagerFactory")
//    public LocalContainerEntityManagerFactoryBean materialEntityManagerFactory(
//            EntityManagerFactoryBuilder builder,
//            @Qualifier("materialJpaDataSource") DataSource dataSource) {
//        return builder
//                .dataSource(dataSource)
//                .packages("com.example.file_management.pojo.material") // 替换为你的实体类所在的包
//                .persistenceUnit("material")
//                .build();
//    }
//
//    @Bean(name = "materialTransactionManager")
//    public PlatformTransactionManager materialTransactionManager(
//            @Qualifier("materialEntityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory) {
//        return new JpaTransactionManager(entityManagerFactory.getObject());
//    }
//}

